<?php

namespace View;

class FriendView {
	
	private $m_user = 'user';
	private $m_searchButton = 'searchButton';
	private $m_addFriendButton = 'addFriendButton';
	
	private static $User="User";
	
	//Returnerar sökformulär
	public function SearchBox() {
		    return 
		    '<div id="search">
			    <form method="post">
				    <fieldset>
						Search for user: <input type="text" name="'.$this->m_user.'" /><br />
						<input type="submit" value="Search" id="searchButton" name="'.$this->m_searchButton.'"/>
					</fieldset>
				</form>
			</div>';
	}
	//Returnerar knapp för att lägga till vän
	public function AddFriendButton() {
		  	return 
		  	'<form method="post">
			  		<input type="submit" value="Add Friend" id="friendButton"name="'.$this->m_addFriendButton.'" />
			 </form>';
	}
	
	//Returnerar vännen
	public function GetUser(){
		
		if (isset($_POST[$this->m_user])){
			$_SESSION[self::$User] = $_POST[$this->m_user];
			 session_write_close();
			return $_POST[$this->m_user];
		} 
		if (empty($_POST[$this->m_user])) {
			$ret = $_SESSION[self::$User];
			return $ret;
    	}
		if (empty($_POST[$this->m_user])) {
        	return false;
    	}
	}
	//Har användaren klickat på sök
	public function TriedToSearch(){
		if (isset($_POST[$this->m_searchButton])){
			return true;
		}
		return false;
	}
	//Har användaren klickat på lägg till vän
	public function TriedToAdd(){
		if (isset($_POST[$this->m_addFriendButton])){
			return true;
		}
		return false;
	}
	
	//Fel/Rätt meddelanden
	public function SearchSuccess(){
		$message = "<p id='result'>Result:" . $this->GetUser(). "</p>";
		return $message;
	}
	
	public function SearchFailed(){
		$message = "<p class='friendMessage'>There is no user with that username</p>";
		return $message;
	}
	
	public function AlreadyFriend(){
		$message = "<p class='friendMessage'>You are already friend with this user</p>";
		return $message;
	}
	
	public function ErrorAddFriend(){
		$message = "<p class='friendMessage>'Something went wrong adding the friend</p>";
		return $message;
	}
	
	public function SuccessAddFriend(){
		$message = "<p class='friendMessage'>Friend added!</p>";
		return $message;
	}
	
}
	